<template>
	<div class="system-menu-dialog-container">
		<el-dialog :rules="rules" :title="state.dialog.title" v-model="state.dialog.isShowDialog" width="769px">
			<el-form ref="menuDialogFormRef" :model="ruleForm" size="default" label-width="120px">
				<el-row :gutter="35">
					<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
						<el-form-item label="厂商编号：" prop="number" :rules="rules.number" :label-width="200">
							<el-input size="default"  placeholder="厂商编号" style="max-width: 400px" v-model="ruleForm.number"> </el-input>
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
						<el-form-item label="厂商名称：" prop="name" :rules="rules.name" :label-width="200">
							<el-input size="default"  placeholder="厂商名称" style="max-width: 400px" v-model="ruleForm.name"> </el-input>
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
			<template #footer>
				<span class="dialog-footer">
					<el-button @click="onCancel" size="default">取 消</el-button>
					<el-button type="primary" @click="onSubmit" size="default">{{ state.dialog.submitTxt }}</el-button>
				</span>
			</template>
		</el-dialog>
	</div>
</template>

<script setup lang="ts" name="systemMenuDialog">
import { defineAsyncComponent, defineExpose,reactive, onMounted, ref,watch,defineProps } from 'vue';
import {  ElMessage, type FormRules } from 'element-plus'
import {MansAPI} from "/@/api/fun/manufacturer/index"
const ManApi = MansAPI()

const props = defineProps(['tableData',"disabled"])
// 定义子组件向父组件传值/事件
const emit = defineEmits(['refresh']);
const disabledFlag = ref<Boolean>(false)
const menuDialogFormRef = ref()
// dx定义start

	interface RuleForm {
		number:string,
		name:string,
	}
	const ruleForm = ref({
		number:"",
		name:"",
	})
	
	watch(props,(newVal,oldVal)=>{
		ruleForm.value = newVal.tableData
		disabledFlag.value = newVal.disabled
	})
	const rules = reactive<FormRules<RuleForm>>({
		number:[
			{ required: true, message: '厂商编号', trigger: 'blur' },
		],
		name:[
			{ required: true, message: '厂商名称', trigger: 'blur' },
		],
		
	})








// dx定义end
const state = reactive({
	dialog: {
		isShowDialog: false,
		type: '',
		title: '',
		submitTxt: '',
	},
});


// 打开弹窗
const openDialog = () => {
		state.dialog.title = '新增设备厂商';
		state.dialog.submitTxt = '新 增';
		state.dialog.isShowDialog = true;
};
// 关闭弹窗
const closeDialog = () => {
	menuDialogFormRef.value.resetFields();
	state.dialog.isShowDialog = false;
};

// 取消
const onCancel = () => {
	closeDialog();
};
// 提交
const onSubmit = (async() => {
		const res = await ManApi.addMan(ruleForm.value);
		if(res.isSuccess){
			ElMessage.success('添加成功')
			closeDialog(); // 关闭弹窗
			emit('refresh');
		}else{
			ElMessage.error(res.returnMsg)
		}
	
});
// 页面加载时
onMounted(() => {
	
});

// 暴露变量
defineExpose({
	openDialog,
});
</script>
